from page.focus_project_page import FocusProjectPage
from common.page import IOS, XPATH
import time as t


class FocusSurveyPage(FocusProjectPage):

    def publish_vote(self, flag=1):  # flag用于控制单选多选
        self.find_button("发布").click()
        self.find_button("投票").click()
        # self.get_frame_center_and_click(self.find_static_text(string="请输入标题"), flag=0)
        # self.find_static_text(string="请输入标题").send_keys("App自动化测试发布%s选投票" % ('单' if flag else '多'))
        self.find_static_text("请输入标题（2-30个字）").click()
        self.find_static_text("请输入标题（2-30个字）").send_keys("App自动化测试发布%s选投票" % ('单' if flag else '多'))
        for i in range(1, 4):
            # self.get_frame_center_and_click(
            #     self.find_element(XPATH, "//XCUIElementTypeTextField[starts-with(@value,'选项%d')]" % i),
            #     flag=0
            # )
            self.find_element(
                XPATH, "//XCUIElementTypeTextField[starts-with(@value,'选项%d')]" % i
            ).send_keys("这是选项%d。。" % i)
        self.swipe(170,31,170,31)  # 点击其他区域以收回键盘
        self.find_static_text("投票结束时间").click()
        self.get_frame_center_and_swipe((XPATH, "//XCUIElementTypePickerWheel[@value='今天']"))
        self.find_button("确定").click()
        self.find_static_text("选择方式").click()

        if flag:
          self.find_static_text("单选").click()
        else:
          self.find_static_text("多选").click()
        self.find_static_text(string="确定").click()
        self.find_button("确定").click()
        t.sleep(4)
        self.find_button(string="common back dark icon",contains_flag=1).click()
        self.find_button(string="数学班",contains_flag=1).click()

    def submit_vote(self, flag=1):  # flag用于控制单选多选
        self.find_element(IOS, "type == 'XCUIElementTypeStaticText' AND "
                               "name CONTAINS '%s选投票'" % ('单' if flag else '多')).click()
        # self.find_static_text("未提交").click()
        self.find_static_text(string="选项1", attr="value", contains_flag=1).click()
        if not flag:
            self.find_static_text(string="选项2", attr="value", contains_flag=1).click()
        self.find_button("投票").click()
        self.find_button(string="确定",contains_flag=1).click()
        t.sleep(3)
        self.find_button(string="common back dark icon", contains_flag=1).click()
        self.find_button(string="common back dark icon", contains_flag=1).click()
        self.find_button(string="数学班", contains_flag=1).click()


if __name__ == "__main__":
    test = FocusSurveyPage()
    t.sleep(5)
    test.enter_project()
    test.enter_tools("调研")
    # 管理员
    test.publish_vote()
    # test.publish_vote(0)
    # 学员
    # test.submit_vote()
    # test.submit_vote(0)
